package controller;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import core.CompressedChar;
import core.FileAnalysis;
import core.Node;

/**
 * @author Mostafa Mahmod Mahmod Eweda
 * <pre>mostafa_eweda17@yahoo.com</pre>
 * @since JDK 1.6
 * @version 1.0
 * 
 * The Generator of the default table used for compressing 
 * 
 * @see CompressedChar
 * @see FileAnalysis
 */
public class DefaultTableGenerator
{
	public static void main(String[] args)
	{
		Controller controller = Controller.getInstance();
		File folder = new File("D:\\different files");
		FileAnalysis analyse = new FileAnalysis("");
		for (File f : folder.listFiles())
		{
			analyse.setFile(f);
			analyse.collectStatistics();
		}
		// System.out.println();
		Node[] nodes = analyse.constructStatistics();
		controller.setRoot(analyse.constructTree(nodes)); // generate the root of the tree
		CompressedChar[] table = analyse.constructTable();
		try {
			ObjectOutputStream outStream = new ObjectOutputStream(new FileOutputStream("default table.3ew"));
			outStream.writeObject(table);
			outStream.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
